<?php
namespace app\models;
use common\component\tool\Tool;


class Message extends Basic
{
    
    public static function tableName()
    {
        return '{{%message}}';
    }

    public function rules()
    {
        return [
            ['app_id', 'required', 'message' => 'app_id不能为空', 'on' => 'add'],
            ['app_id', 'integer', 'message' => 'app_id必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'app_id最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'app_id最大存储18446744073709551615'],
            ['title', 'string', 'message' => 'title必须是字符串',
                                'max' => 32, 'tooLong' => 'title最长32位'],
            ['name', 'string', 'message' => 'name必须是字符串',
                                'max' => 8, 'tooLong' => 'name最长8位'],
            ['companyname', 'string', 'message' => 'companyname必须是字符串',
                                'max' => 32, 'tooLong' => 'companyname最长32位'],
            ['phone', 'string', 'message' => 'phone必须是字符串',
                                'max' => 16, 'tooLong' => 'phone最长16位'],
            ['contents', 'default', 'value' => ''],
            ['contents', 'string', 'message' => 'contents必须是字符串'],
            ['add_time', 'default', 'value' => '1000-01-01 00:00:00'],
            ['add_time', 'date', 'format'=>'yyyy-MM-dd HH:mm:ss', 'message' => 'add_time非yyyy-MM-dd HH:mm:ss格式'],
            ['reply', 'integer', 'message' => 'reply必须为数字，或数字字符串'],
            ['reply', 'in', 'range' => array(1, 2), 'message' => 'reply值必须在1~2中选择'],
            ['member_id', 'required', 'message' => 'member_id不能为空', 'on' => 'add'],
            ['member_id', 'integer', 'message' => 'member_id必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'member_id最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'member_id最大存储18446744073709551615'],
            ['replyname', 'string', 'message' => 'replyname必须是字符串',
                                'max' => 8, 'tooLong' => 'replyname最长8位'],
            ['reply_time', 'default', 'value' => '1000-01-01 00:00:00'],
            ['reply_time', 'date', 'format'=>'yyyy-MM-dd HH:mm:ss', 'message' => 'reply_time非yyyy-MM-dd HH:mm:ss格式'],
        ];
    }


    /*添加*/
    public function addMessage($data)
    {
        // P($data);
        $data['Message']['add_time'] = date('Y-m-d H:i:s', time());
        if($this->load($data) and $this->validate()){
            // P($this);
            if($this->save(false)){
                return true;
            }
        }
        return false;
    }

    
}